package net.zjitc.reflect;

import java.lang.reflect.Method;

/**
 * Created by Administrator on 2017/11/1.
 */
public class TestTwo {

    public static void main(String[] args) throws Exception {
        /*通过类名拿到类对象*/
        Class clazz= Class.forName("net.zjitc.reflect.Person");
        //通过类对象创造实例
        Person p = (Person) clazz.newInstance();

        //反射调用p的speak方法 ？？？
        /**
         * 1. 类对应的实例 p
         * 2. 通过类对象，拿到的是方法对象
         * 3. 回调
         */
        Method m = clazz.getMethod("speak",String.class,int.class);
        m.invoke(p,"zs",300);


        System.out.println(p);

    }
}
